/*
 *   Copyright (c) 2025 
 *   All rights reserved.
 */
import Fontmin from "fontmin";
import path from "node:path";
import fs from "node:fs";

// 字体子集化压缩

// 示例文字
// const text = "hello world";
const text = fs
  .readFileSync(path.join(import.meta.dirname, "../index.html"))
  .toString();
console.log(text);

const fontPath = path.resolve(
  import.meta.dirname,
  "../fonts/AlimamaShuHeiTi-Bold.ttf"
);
const destPath = path.resolve(import.meta.dirname, "../dist");

const fontmin = new Fontmin()
  .src(fontPath)
  .use(
    Fontmin.otf2ttf({
      text,
    })
  )
  .use(
    Fontmin.glyph({
      text,
    })
  )
  .use(Fontmin.ttf2eot())
  .use(Fontmin.ttf2woff({ deflate: true }))
  .use(Fontmin.ttf2woff2())
  .use(Fontmin.ttf2svg())
  .dest(destPath);

fontmin.runAsync();
